bug fix: DateTimeSensor can't render jinja template if use native obj#50744
Merged
Lee-W merged 7 commits intoapache:mainfrom May 27, 2025
Merged
Conversation
Lee-W
approved these changes
May 19, 2025
Lee-W
approved these changes
May 20, 2025
Contributor
Author
uranusjr
reviewed
May 26, 2025
providers/standard/src/airflow/providers/standard/sensors/date_time.py
Outdated
Show resolved
Hide resolved
Contributor
|
For whatever it's worth, looks good to me. Thanks for addressing the issue! I can't wait to remove all those |
Contributor
Author
|
I'm so glad I could help with this issue 😄 |
sanederchik
pushed a commit
to sanederchik/airflow
that referenced
this pull request
Jun 7, 2025
…apache#50744) * fix bug: can't render jinja template if use native obj * re-order `from airflow.utils import timezone` * make `_moment` as a property * fix unit test * remove the unnecessary pendulum object
jose-lehmkuhl
pushed a commit
to jose-lehmkuhl/airflow
that referenced
this pull request
Jul 11, 2025
…apache#50744) * fix bug: can't render jinja template if use native obj * re-order `from airflow.utils import timezone` * make `_moment` as a property * fix unit test * remove the unnecessary pendulum object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #38336
🐞 Problem
This is quite an interesting case.
render_template_as_native_obj=True, the Jinja expression is stored as a raw string whenDateTimeSensorAsyncis instantiated{{ (data_interval_end + macros.timedelta(minutes=1)) }}→ falls through line 91 and is kept as‑is.pendulum.DateTimeobject.When
execute()callstimezone.parseexpects a string and raisesTypeError.✅ Fix
_moment()thatself.target_timedirectly if it is already adatetime/pendulum.DateTime;timezone.parse.timezone.parse(self.target_time)with_moment().render_template_as_native_obj=False.📝Example DAG (runs successfully after this patch)